#pragma once

#include <iostream>
#include <functional>
#include <string>
#include <cstring>
#include <memory>
#include <unistd.h>

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#include <fcntl.h>

enum ExitCode
{
    OK = 0,
    USAGE_ERR,
    SOCKET_ERR,
    BIND_ERR,
    LISTEN_ERR,
    CONNECT_ERR,
    FORK_ERR,
    OPEN_ERR,
    EPOLL_CREATE_ERR,
    EPOLL_CTL_ERR
};

class NoCopy
{
public:

    NoCopy(){}
    ~NoCopy(){}
    NoCopy(const NoCopy&) = delete;
    const NoCopy& operator=(const NoCopy&) = delete;
};

#define defaultport 8080

#define CONV(addr) ((struct sockaddr*)&addr)

//设置非阻塞函数
void SetNonBlock(int fd)
{
    int f1 = fcntl(fd, F_GETFL);
    if(f1 < 0)
    {
        return;
    }
    fcntl(fd, F_SETFL, f1 | O_NONBLOCK);
}